<?php
namespace Plu\Library\Models\Platform\Tag;

use Phalcon\Mvc\Model,
    Phalcon\Db\Column;

class Tag extends Model {

    public $Id;

    public $Name;

    public $Slug;

    public function initialize() {
        $this->setReadConnectionService('db.platform.slave');
    }

    public function getSource() {
        return 'Tag';
    }

    public function getItem($name) {
        $item = self::findFirst(array(
            "Name = :name:",
            "bind" => array(
                'name' => $name
            ),
            "bindTypes" => array(
                'name' => Column::BIND_PARAM_STR
            ),
            "cache"	 => array(
                "lifetime" => 86400,
                "key"	   => sprintf("tag_%d", $roomId)
            )
        ));

        if ($item == false) {
            return [];
        } else {
            return $item->toArray();
        }
    }
}
?>
